package leetcode.tree;

public class Solution2 {

    public boolean isValidBST(TreeNode root) {
        if (root == null) {
            return false;
        } else {
            TreeNode left = root.left;
            TreeNode right = root.right;
            if (left != null && left.val >= root.val) {
                return false;
            }
            if (right != null && right.val <= root.val) {
                return false;
            }
            isValidBST(left);
            isValidBST(right);
        }
        return true;
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(2);
        TreeNode root_left = new TreeNode(1);
        TreeNode root_right = new TreeNode(3);
        //TreeNode root_right_left = new TreeNode(15);
        //TreeNode root_right_right = new TreeNode(7);
        root.left = root_left;
        root.right = root_right;
        //root_right.left = root_right_left;
        //root_right.right = root_right_right;
        System.out.println(new Solution2().isValidBST(root));
    }
}


